<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">

    <title>登录</title>

    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">



    <!-- Custom styles for this template -->
    <link href="navbar-fixed-top.css" rel="stylesheet">

    <style>
        body{
            background-image: url("/avatar/loginbg.jpg");
        }
        .jumbotron{
            margin-top: 20px;
        }
        #title{
            margin-top: 70px;
        }
        .alert{
            margin-top: 20px;
            display: none;
        }
    </style>



</head>

<body>

<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top" style="background: #91C4C7">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">班级说说</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li ><a href="/">全部说说</a></li>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li><a href="/regist">注册</a></li>
                <li class="active"><a href="/login">登录</a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>

<div class="container">

   <h2 id="title" style="color: #5cb85c">登录</h2>
    <!-- Main component for a primary marketing message or call to action -->

    <div class="jumbotron">

        <form>
            <div class="form-group">
                <label for="exampleInputEmail1">用户名</label>
                <input type="text" class="form-control" id="username" placeholder="用户名">
            </div>
            <div class="form-group">
                <label for="exampleInputPassword1">密码</label>
                <input type="password" class="form-control" id="password" placeholder="密码">
            </div>

            <button type="button" id="submit" class="btn btn-default">登录</button>
        </form>
        <div class="alert alert-danger"  role="alert">密码错误</div>
    </div>

</div> <!-- /container -->
<script src="js/jquery-1.11.3.min.js"></script>

<script src="js/bootstrap.min.js"></script>
<script>
    $('.alert').fadeOut();
    $("input").focus(function(){
        $('.alert').fadeOut();
    });
    $('#submit').click(function () {
        if($('#username').val()&&$('#password').val()) {
            $.post("/dologin", {
                'username': $('#username').val(),
                'password': $('#password').val()

            }, function (status) {

                if (status == '1') {
                    //登录成功
                    window.location = '/';
                } else if (status == '-1') {
                    $('.alert').fadeIn();
                    $('.alert').html('没有该用户');
                } else if (status == '-3') {
                    alert('服务器错误');
                } else {

                    $('.alert').fadeIn();

                    $('.alert').html('密码错误');
                }

            });
        }

    })
</script>
</body>
</html>
